package com.googlecode.struts2scope.scope.annotation.scanner;

import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;

import com.googlecode.struts2scope.scope.ScopeType;
import com.googlecode.struts2scope.scope.annotation.Scope;

public class ScopeAnnotationScanner {

	public Set<FieldMetadata> scanClass(Class<?> actionClass) {
		Set<FieldMetadata> fieldsWithScopeAnnotation = new HashSet<FieldMetadata>();
		Field[] fields = actionClass.getDeclaredFields();
		for (Field field : fields) {
			if (field.isAnnotationPresent(Scope.class)) {
				Scope scope = field.getAnnotation(Scope.class);
				ScopeType scopeType = scope.type();
				String key = scope.key();
				FieldMetadata fieldMetadata = new FieldMetadata(field, scopeType, key);
				fieldsWithScopeAnnotation.add(fieldMetadata);
			}
		}
		return fieldsWithScopeAnnotation;
	}
}
